// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed

class UTXFormatter implements vscode.DocumentFormattingEditProvider {
	provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
		// TODO: 实现具体格式化逻辑
		return [];
	}
}

export function activate(context: vscode.ExtensionContext) {
	// 注册文档格式化器
	context.subscriptions.push(
		vscode.languages.registerDocumentFormattingEditProvider(
			[{ language: 'uvue' }, { language: 'uts' }],
			new UTXFormatter()
		)
	);

	// 初始化诊断功能
	const diagnosticCollection = vscode.languages.createDiagnosticCollection('uniappx');
	context.subscriptions.push(diagnosticCollection);

	// 监听文档变更
	vscode.workspace.onDidOpenTextDocument(document => updateDiagnostics(document, diagnosticCollection));
	vscode.workspace.onDidSaveTextDocument(document => updateDiagnostics(document, diagnosticCollection));
}

function updateDiagnostics(document: vscode.TextDocument, collection: vscode.DiagnosticCollection) {
	// TODO: 实现错误检查逻辑
	const diagnostics: vscode.Diagnostic[] = [];
	collection.set(document.uri, diagnostics);
}

// This method is called when your extension is deactivated
export function deactivate() {}
